package com.hzncc.scaffold.controller.Front.Reply;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.date.DateUtil;
import com.hzncc.scaffold.core.ResultT;
import com.hzncc.scaffold.entity.Other.Reply;
import com.hzncc.scaffold.entity.Vo.CommitReplyVo;
import com.hzncc.scaffold.service.ReplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @Author: DrunkBear
 * @Date: 2022-06-22 16:19
 * @Description: null
 */
@Api(tags = "前台接口-回复")
@RequestMapping("/course/reply")
public class ReplyController {

    @Autowired
    ReplyService replyService;

    @PostMapping("/commit")
    @ApiOperation("问答回复")
    private ResultT commit(@RequestBody CommitReplyVo commitReplyVo){

        Reply reply = new Reply();
        reply.setAskId(Integer.parseInt(commitReplyVo.getAskId()));
        reply.setUserId(StpUtil.getLoginIdAsInt());
        reply.setContent(commitReplyVo.getContent());
        reply.setCreateTime(DateUtil.now());

        boolean save = replyService.save(reply);

        if(save){
            return ResultT.success("操作成功");
        }else {
            return ResultT.fail("操作失败");
        }

    }
}
